package com.ruoyi.web.controller.ydz;

import java.util.*;

import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.util.Internal;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Clinical;
import com.ruoyi.web.service.IClinicalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 临床招募Controller
 *
 *
 * @author drx
 * @date 2024-04-08
 */
@Controller
@Api(tags = "临床招募")
@RequestMapping({"/ydz/clinical","/api/clinical"})
public class ClinicalController extends BaseController
{
    private String prefix = "ydz/clinical";

    @Resource
    private IClinicalService clinicalService;

    @RequiresPermissions("ydz:clinical:view")
    @GetMapping()
    public String clinical()
    {
        return prefix + "/clinical";
    }

    /**
     * 查询临床招募列表
     */
    @RequiresPermissions("ydz:clinical:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询临床招募列表")
    public TableDataInfo list(Clinical clinical)
    {
        startPage();
        List<Clinical> list = clinicalService.selectClinicalList(clinical);
        return getDataTable(list);
    }

    /**
     * 查询临床招募列表
     * pc端使用 查询id name 适应症和分期
     */
    @PostMapping("/selectClinicalList")
    @ResponseBody
    @ApiOperation("查询临床招募列表")
    public TableDataInfo selectClinicalList(@RequestBody Clinical clinical)
    {
        startPage();
        List<Clinical> list = clinicalService.getClinicalList(clinical);
        return getDataTable(list);
    }

    /**
     * 导出临床招募列表
     */
    @RequiresPermissions("ydz:clinical:export")
    @Log(title = "临床招募", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出临床招募列表")
    public AjaxResult export(Clinical clinical)
    {
        List<Clinical> list = clinicalService.selectClinicalList(clinical);
        ExcelUtil<Clinical> util = new ExcelUtil<Clinical>(Clinical.class);
        return util.exportExcel(list, "临床招募数据");
    }

    /**
     * 新增临床招募
     */
    @GetMapping("/add")
    @ApiOperation("新增临床招募")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存临床招募
     */
    @ApiOperation("新增保存临床招募")
    @RequiresPermissions("ydz:clinical:add")
    @Log(title = "临床招募", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody Clinical clinical)
    {
        return toAjax(clinicalService.insertClinical(clinical));
    }

    /**
     * 修改临床招募
     */
    @ApiOperation("修改临床招募")
    @RequiresPermissions("ydz:clinical:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Clinical clinical = clinicalService.selectClinicalById(id);
        mmap.put("clinical", clinical);
        return prefix + "/edit";
    }

    /**
     * 修改保存临床招募
     */
    @ApiOperation("修改保存临床招募")
    @RequiresPermissions("ydz:clinical:edit")
    @Log(title = "临床招募", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody Clinical clinical)
    {
        return toAjax(clinicalService.updateClinical(clinical));
    }


    /**
     * 删除临床招募
     */
    @ApiOperation("删除临床招募")
    @RequiresPermissions("ydz:clinical:remove")
    @Log(title = "临床招募", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clinicalService.deleteClinicalByIds(ids));
    }

    /**
     * 获取新闻详情-前端调用
     */
    @ApiOperation("获取临床招募详情")
    @GetMapping("/get/{id}")
    @ResponseBody
    public Clinical get(@PathVariable("id") Long id)
    {
        return clinicalService.selectClinicalById(id);
    }
}